package ylg.com.cn.android_5_0_actvityswitch;

import android.annotation.TargetApi;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.transition.Explode;
import android.transition.Fade;
import android.transition.Slide;
import android.transition.Transition;
import android.view.View;
import android.widget.Button;

/**
 * activity里的布局的切换;
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn1,btn2,btn3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(this);
        btn2 = (Button) findViewById(R.id.btn2);
        btn2.setOnClickListener(this);
        btn3 = (Button) findViewById(R.id.btn3);
        btn3.setOnClickListener(this);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onClick(View v) {
        Transition transition = null;
        Intent intent = null;
        switch (v.getId()){
            case R.id.btn1:
                intent = new Intent(MainActivity.this,Main2Activity.class);
                transition = new Explode();
                break;
            case R.id.btn2:
                //淡入淡出
                intent = new Intent(MainActivity.this,Main3Activity.class);
                transition = new Fade();
                break;
            case R.id.btn3:
                //滑动
                intent = new Intent(MainActivity.this,Main4Activity.class);
                transition = new Slide();
                break;
        }
        transition.setDuration(1000);
        getWindow().setEnterTransition(transition);
        getWindow().setExitTransition(transition);
        getWindow().setReenterTransition(transition);
        getWindow().setReturnTransition(transition);
        startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(MainActivity.this).toBundle());

    }
}
